﻿using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraBars;
using UniMana.Data;
using UniMana.Utils.Data;
using UniMana.Utils.Helper;
namespace UniMana.Win.Leadership
{
    public partial class FrmReport_SubStudent_Address : DevExpress.XtraEditors.XtraForm
    {
        private DBMain m_ReportStudent_Address = new DBMain();
        private const int ACTION_NO = 0;
        DataTable dt = new DataTable();
        int m_iCourseKey = 0;
        int m_iMajorKey = 0;

        public FrmReport_SubStudent_Address()
        {
            InitializeComponent();
            InitControlEvent();
        }
        public void InitControlEvent()
        {
            this.xucBar1.btnPrint_Click +=
                new UniMana.Utils.Controls.xucBar.ButtonClickHandler(
                    this.btnPrint_Click);
            //this.xucBar1.btnExport_Click += 
            //    new UniMana.Utils.Utils.Controls.xucBar.ButtonClickHandler(
            //        this.btnExportExcel_Click);
            //}
        }
        private void btnPrint_Click(object sender, ItemClickEventArgs e)
        {
            compositeLink_HienThi.ShowPreviewDialog();

        }

        private void FrmReportStudent_Address_Load(object sender, EventArgs e)
        {
            this.lueCatalogue_Course.GetData(
                m_ReportStudent_Address.m_DCReadOnly.Catalogue_Courses, 
                "Catalogue_CourseKey", "Name");
            this.lueCatalogue_Major.GetData(
                m_ReportStudent_Address.m_DCReadOnly.Catalogue_Majors, 
                "Catalogue_MajorKey", "Name");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private int CheckInfo()
        {
            if (this.lueCatalogue_Course.EditValue != null && 
                this.lueCatalogue_Major.EditValue != null)
            {

                m_iMajorKey = (int)lueCatalogue_Major.EditValue;
                m_iCourseKey = (int)lueCatalogue_Course.EditValue;
                return 1;
            }
            if (this.lueCatalogue_Course.EditValue != null && 
                this.lueCatalogue_Major.EditValue == null)
            {
                m_iCourseKey = (int)lueCatalogue_Course.EditValue;
                return 2;
            }


            if (this.lueCatalogue_Course.EditValue == null && 
                this.lueCatalogue_Major.EditValue != null)
            {
                m_iMajorKey = (int)lueCatalogue_Major.EditValue;
                return 3;
            }
            else
            {
                return 0;
            }



        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnView_Click(object sender, EventArgs e)
        {
            //if (this.lueCatalogue_Course.EditValue != null &&
            //this.lueCatalogue_Major.EditValue!=null )
            //{
            //   grcStudent_Address.DataSource = 
            //m_ReportStudent_Address.m_DCReadOnly.Catalogue_Cities.Student_City(
            //    m_ReportStudent_Address.m_DCReadOnly.Catalogue_Courses,
            //    m_ReportStudent_Address.m_DCReadOnly.Training_Student_Classes,
            //    m_ReportStudent_Address.m_DCReadOnly.Training_Classes,
            //    m_ReportStudent_Address.m_DCReadOnly.Catalogue_Majors,
            //    m_ReportStudent_Address.m_DCReadOnly.Training_Students,
            //    this.lueCatalogue_Course.GetIntValue(),
            //    this.lueCatalogue_Major.GetIntValue());
            //   grvStudent_Address.ExpandAllGroups();         
            //}
            //if (this.lueCatalogue_Course.EditValue != null && 
            //this.lueCatalogue_Major.EditValue == null)
            //{
            //    grcStudent_Address.DataSource = 
            m_ReportStudent_Address.m_DCReadOnly.Catalogue_Cities.Student_City_Major(
                m_ReportStudent_Address.m_DCReadOnly.Catalogue_Courses,
                m_ReportStudent_Address.m_DCReadOnly.Training_Student_Classes,
                m_ReportStudent_Address.m_DCReadOnly.Training_Classes,
                m_ReportStudent_Address.m_DCReadOnly.Catalogue_Majors,
                m_ReportStudent_Address.m_DCReadOnly.Training_Students,
                this.lueCatalogue_Course.GetIntValue());
            //    grvStudent_Address.ExpandAllGroups();
            //}
            //if (this.lueCatalogue_Course.EditValue == null && this.lueCatalogue_Major.EditValue != null)
            //{
            //    grcStudent_Address.DataSource = 
            m_ReportStudent_Address.m_DCReadOnly.Catalogue_Cities.Student_City_Major(
                m_ReportStudent_Address.m_DCReadOnly.Catalogue_Courses, 
                m_ReportStudent_Address.m_DCReadOnly.Training_Student_Classes, 
                m_ReportStudent_Address.m_DCReadOnly.Training_Classes, 
                m_ReportStudent_Address.m_DCReadOnly.Catalogue_Majors, 
                m_ReportStudent_Address.m_DCReadOnly.Training_Students, 
                this.lueCatalogue_Major.GetIntValue());
            //    grvStudent_Address.ExpandAllGroups();
            //}

            if (CheckInfo() == 1)
            {
                try
                {

                    //them so thu tu vao luoi
                    DataTable dt = 
                        m_ReportStudent_Address.m_DCReadOnly.Catalogue_Cities.Student_City(
                        m_ReportStudent_Address.m_DCReadOnly.Catalogue_Courses, 
                        m_ReportStudent_Address.m_DCReadOnly.Training_Student_Classes, 
                        m_ReportStudent_Address.m_DCReadOnly.Training_Classes, 
                        m_ReportStudent_Address.m_DCReadOnly.Catalogue_Majors, 
                        m_ReportStudent_Address.m_DCReadOnly.Training_Students, 
                        this.lueCatalogue_Course.GetIntValue(), 
                        this.lueCatalogue_Major.GetIntValue()).ToDataTable();
                    
                    dt.Columns.Add("STT");
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        dt.Rows[i]["STT"] = i + 1;
                    }
                    this.grcStudent_Address.DataSource = dt;
                }
                catch { MessageBox.Show("Lỗi", "Thông báo"); }
            }
            else
            {
                if (CheckInfo() == 2)
                {
                    try
                    {

                        //them so thu tu vao luoi
                        DataTable dt = 
                            m_ReportStudent_Address.m_DCReadOnly.Catalogue_Cities.Student_City_Course(
                            m_ReportStudent_Address.m_DCReadOnly.Catalogue_Courses,
                            m_ReportStudent_Address.m_DCReadOnly.Training_Student_Classes, 
                            m_ReportStudent_Address.m_DCReadOnly.Training_Classes,
                            m_ReportStudent_Address.m_DCReadOnly.Catalogue_Majors, 
                            m_ReportStudent_Address.m_DCReadOnly.Training_Students, 
                            lueCatalogue_Course.GetIntValue()).ToDataTable();


                        dt.Columns.Add("STT");
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            dt.Rows[i]["STT"] = i + 1;
                        }
                        this.grcStudent_Address.DataSource = dt;
                    }
                    catch { MessageBox.Show("Lỗi", "Thông báo"); }

                }
                else
                {
                    if (CheckInfo() == 3)
                    {
                        try
                        {

                            //them so thu tu vao luoi
                            DataTable dt = 
                                m_ReportStudent_Address.m_DCReadOnly.Catalogue_Cities.Student_City_Major(
                                m_ReportStudent_Address.m_DCReadOnly.Catalogue_Courses, 
                                m_ReportStudent_Address.m_DCReadOnly.Training_Student_Classes, 
                                m_ReportStudent_Address.m_DCReadOnly.Training_Classes, 
                                m_ReportStudent_Address.m_DCReadOnly.Catalogue_Majors, 
                                m_ReportStudent_Address.m_DCReadOnly.Training_Students, 
                                lueCatalogue_Major.GetIntValue()).ToDataTable();
                            //gridColumn3.Visible = false;
                            dt.Columns.Add("STT");
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                dt.Rows[i]["STT"] = i + 1;
                            }
                            this.grcStudent_Address.DataSource = dt;
                        }
                        catch { MessageBox.Show("Lỗi", "Thông báo"); }

                    }
                }
            }

        }
    }

}
